package com.pb.infra.dynamicSetting.dynamicSettingTable.controller;

import com.pb.infra.dynamicSetting.dynamicSettingTable.dto.TableEditDTO;
import com.pb.infra.dynamicSetting.dynamicSettingTable.dto.TableSearchDTO;
import com.pb.infra.dynamicSetting.dynamicSettingTable.service.DynamicSettingTableService;
import com.pb.infra.oth.entity.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 动态表格控制层
 * @author JYF
 */
@RestController
@Slf4j
@RequestMapping("/dynamicSetting/table")
public class DynamicSettingTableController {


    @Resource
    private DynamicSettingTableService dynamicSettingTableService;
    /**
     * 获取表格结构
     * @param tableId
     * @return
     */
    @PostMapping("/getTableStructure")
    public Result getTableStructure(@RequestBody String tableId) {
        return dynamicSettingTableService.getTableStructure(tableId);
    }

    /**
     * 获取动态构建出的表格数据
     * @param dto
     * @return
     */
    @PostMapping("/data/list")
    public Result tableDataList(@RequestBody TableSearchDTO dto) {
        return dynamicSettingTableService.tableDataList(dto);
    }

    /**
     * 删除
     * @param dto 编辑对象
     * @return 结果
     */
    @PostMapping("/data/del")
    public Result delTableData(@RequestBody TableEditDTO dto) {
        return dynamicSettingTableService.delTableData(dto.getTableId(),dto.getEditParam());
    }

    /**
     * 添加
     * @param dto 编辑对象
     * @return 结果
     */
    @PostMapping("/data/add")
    public Result addTableData(@RequestBody TableEditDTO dto) {
        return dynamicSettingTableService.addTableData(dto.getTableId(),dto.getEditParam());
    }

    /**
     * 修改
     * @param dto 编辑对象
     * @return 结果
     */
    @PostMapping("/data/upd")
    public Result updTableData(@RequestBody TableEditDTO dto) {
        return dynamicSettingTableService.updTableData(dto.getTableId(),dto.getEditParam());
    }

    @PostMapping("/data/export")
    public void dataExport(@RequestBody TableSearchDTO dto, HttpServletResponse response) throws Exception {
        this.dynamicSettingTableService.dataExport(dto,response);
    }

    @GetMapping("/data/queryIMPId")
    public Result queryIMPId() {
        return dynamicSettingTableService.queryIMPId();
    }
}
